package com.hiultra.archive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hiultra.common.constant.UserConstants;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.archive.domain.SimfExamineSetup;
import com.hiultra.archive.service.ISimfExamineSetupService;
import com.hiultra.common.utils.poi.ExcelUtil;
import com.hiultra.common.core.page.TableDataInfo;

/**
 * 审批步骤Controller
 * 
 * @author ls
 * @date 2023-09-25
 */
@RestController
@RequestMapping("/examine/examineSetup")
public class SimfExamineSetupController extends BaseController
{
    @Autowired
    private ISimfExamineSetupService simfExamineSetupService;

    /**
     * 查询审批步骤列表
     */
    @PreAuthorize("@ss.hasPermi('examine:examineSetup:list')")
    @GetMapping("/list")
    public TableDataInfo list(SimfExamineSetup simfExamineSetup)
    {
        startPage();
        List<SimfExamineSetup> list = simfExamineSetupService.selectSimfExamineSetupList(simfExamineSetup);
        return getDataTable(list);
    }

    /**
     * 导出审批步骤列表
     */
    @PreAuthorize("@ss.hasPermi('examine:examineSetup:export')")
    @Log(title = "审批步骤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SimfExamineSetup simfExamineSetup)
    {
        List<SimfExamineSetup> list = simfExamineSetupService.selectSimfExamineSetupList(simfExamineSetup);
        ExcelUtil<SimfExamineSetup> util = new ExcelUtil<SimfExamineSetup>(SimfExamineSetup.class);
        util.exportExcel(response, list, "审批步骤数据");
    }

    /**
     * 获取审批步骤详细信息
     */
    @PreAuthorize("@ss.hasPermi('examine:examineSetup:query')")
    @GetMapping(value = "/{setupId}")
    public AjaxResult getInfo(@PathVariable("setupId") Long setupId)
    {
        return AjaxResult.success(simfExamineSetupService.selectSimfExamineSetupBySetupId(setupId));
    }

    /**
     * 新增审批步骤
     */
    @PreAuthorize("@ss.hasPermi('examine:examineSetup:add')")
    @Log(title = "审批步骤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SimfExamineSetup simfExamineSetup)
    {
        if (UserConstants.NOT_UNIQUE.equals(simfExamineSetupService.checkExamineSetupNameUnique(simfExamineSetup))) {
            return AjaxResult.error("新增当前审批流程下步骤'" + simfExamineSetup.getSetupName() + "'失败，步骤已存在");
        }
        if (UserConstants.NOT_UNIQUE.equals(simfExamineSetupService.checkExamineSortNoUnique(simfExamineSetup))) {
            return AjaxResult.error("新增当前审批步骤'" + simfExamineSetup.getSetupName() + "'失败，排序已存在");
        }
        return toAjax(simfExamineSetupService.insertSimfExamineSetup(simfExamineSetup));
    }

    /**
     * 修改审批步骤
     */
    @PreAuthorize("@ss.hasPermi('examine:examineSetup:edit')")
    @Log(title = "审批步骤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SimfExamineSetup simfExamineSetup)
    {
        return toAjax(simfExamineSetupService.updateSimfExamineSetup(simfExamineSetup));
    }

    /**
     * 删除审批步骤
     */
    @PreAuthorize("@ss.hasPermi('examine:examineSetup:remove')")
    @Log(title = "审批步骤", businessType = BusinessType.DELETE)
	@DeleteMapping("/{setupIds}")
    public AjaxResult remove(@PathVariable Long[] setupIds)
    {
        return toAjax(simfExamineSetupService.deleteSimfExamineSetupBySetupIds(setupIds));
    }
}
